<template>
  <a-modal v-model:visible="visible" title="密码" @ok="handleSubmit" @cancel="cancel">
    <div style="margin: 30px 0px">
      <BasicForm @register="registerForm" @submit="handleSubmit" />
    </div>
  </a-modal>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { resetgateway } from '/@/api/sys/gateway/gateway';
  import { fromConfig } from './pwdfromData';
  import Bus from '/@/utils/helper/eventbus';
  export default defineComponent({
    components: { BasicForm },
    props: {
      method: { type: String, defaultValue: 'add' },
      formData: { type: Object },
    },
    emits: ['success'],
    setup(_, { emit }) {
      const [registerForm, { validate, resetFields }] = useForm(fromConfig);
      const visible = ref(false);
      async function handleSubmit() {
        Bus.$emit('showspin', true);
        const values = await validate();
        await resetgateway(values).then((e) => {
          Bus.$emit('showspin', false);
          visible.value = false;
          emit('success');
          resetFields();
        });
      }
      //关闭
      function cancel() {
        visible.value = false;
        resetFields();
      }

      return { registerForm, handleSubmit, visible, cancel };
    },
  });
</script>
